package org.jie.guider.framework.mvc.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author LiJie
 */
@Component
public class SpringApplication implements ApplicationContextAware {

    private static ApplicationContext APPLICATION;

    private SpringApplication() {
    }

    public static <T> T getBean(Class<T> clz) {
        return APPLICATION.getBean(clz);
    }

    public static <T> T getBean(String name, Class<T> clz) {
        return APPLICATION.getBean(name, clz);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
        throws BeansException {
        APPLICATION = applicationContext;
    }
}
